<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function getSum(...arr) {
            // console.log(arguments);
            // arguments.push(100);
            // console.log(arguments);
            // console.log(arr);
            // arr.push(100);
            // console.log(arr);
            var sum = 0;
            // for (var i = 0; i < arr.length; i++) {
            //   sum += arr[i]
            // }
            for (var i of arr) {
                sum += i
            }
            console.log(sum);
        }
        // 等价于 ...[1,2,3,4]
        // getSum(1, 2, 3, 4, 5, 6)
        getSum(...[1, 2, 3, 4])

        var arr1 = [11, 100, 90, 40];
        console.log(Math.max(11, 100, 90, 40));
        // ...arr1 其实相当于将这个数组拆分成 11,100,90,40
        console.log(...[11, 100, 90, 40]);
        console.log(Math.max(...arr1));

        var a = 10;
        var b = 100;
        a = a + b; // a = 110 b = 100
        b = a - b; // a = 110  b = 10
        a = a - b; // a = 100 b = 10
        console.log(a, b);
        [a, b] = [b, a];
        console.log(a, b);


        var [num1, num2, num3, num4] = [11, 100, 90, 40];
        console.log(num1, num2, num3, num4);

        console.log('zzw' > 'dengmin');
        console.log('like' < 'zzw');
        console.log([1, 2, 3] < [1, 2]);

        // 如果前面一个数据大于后面的数据  就实现位置的交换
        // a - b > 0
        // if (arr[j] > arr[j + 1]) {
        //     [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]]
        // }

        var arr = [11, 2, 33, 4].sort(function(a, b) {
            return a - b
        })
        console.log(arr);
    </script>
</body>

</html>